<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <!-- 引入Vue -->
    <script src="https://cdn.bootcss.com/vue/2.6.10/vue.min.js"></script>
    <!-- 引入样式 -->
    <link href="https://cdn.bootcss.com/element-ui/2.15.0/theme-chalk/index.css" rel="stylesheet">
    <!-- 引入组件库 -->
    <script src="https://cdn.bootcdn.net/ajax/libs/element-ui/2.15.0/index.min.js"></script>

    <script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.js"></script>

<!--    <script src="/js/axios.min.js"></script>-->

</head>
<body id = "body">
<div  id="app" v-loading="loading">
    <el-container >
        <el-header class="c_head">
            <div class="c_header_left">
                <img src="../static/img/yegs.png" style="width: 200px;height: 60px"/>
            </div>
            <div class="c_header_left">
                <el-menu
                        mode="horizontal"
                        active-text-color="rgb(35, 98, 251)">
<!--                    <el-menu-item index="1" >-->
<!--                       <div class="c_menu_item" @click="type = 'machining'">-->
<!--                           加工单-->
<!--                       </div>-->
<!--                    </el-menu-item>-->
<!--                    <el-menu-item index="2">-->
<!--                        <div class="c_menu_item">-->
<!--                            基础数据-->
<!--                        </div>-->
<!--                    </el-menu-item>-->
<!--                    <el-menu-item index="3">-->
<!--                        <div class="c_menu_item">-->
<!--                        基础数据-->
<!--                        </div>-->
<!--                    </el-menu-item>-->
                </el-menu>
            </div>
            <div class="c_header_right">
                <el-button @click="editVisible=true">设置</el-button>
            </div>
        </el-header>
        <el-main >
            <!-------------------------------用户密码修改 ----------------------down ------------------->
            <div v-show="editVisible">
                <el-dialog title="编辑"   :visible.sync="editVisible" class="c_dialog" :close-on-click-modal="false">
                    <el-form ref="muser" :model="muser" :rules="len6" class="c_form" label-width="80px"  label-position="left" size="small" >
                        <el-form-item label="用户账号" prop="fuserID" >
                            {{muser.fuserID}}
                        </el-form-item>
                        <el-form-item label="用户名" prop="fname" >
                            {{muser.fname}}
                        </el-form-item>
                        <el-form-item label="原密码" prop="password">
                            <el-input v-model="muser.password"  :type="passwordType"/>
                        </el-form-item>
                        <el-form-item label="新密码" prop="n_password1">
                            <el-input v-model="muser.n_password1"  :type="passwordType"/>
                        </el-form-item>
                        <el-form-item label="确认密码" prop="n_password2">
                            <el-input v-model="muser.n_password2"  :type="passwordType"/>
                        </el-form-item>
                        <!-------------------------------按钮 ----------------------down------------------->
                        <div v-show="editVisible" class="c_form_btn">
                            <el-button class="hand-btn" type="cancel" @click="editVisible = !editVisible">取消</el-button>
                            <el-button class="hand-btn" type="primary" @click="saveMuser">保存</el-button>
                        </div>
                        <!-------------------------------按钮 ----------------------up ------------------->
                    </el-form>
                </el-dialog>
            </div>
            <!-------------------------------用户密码修改----------------------up ------------------->
            <!-------------------------------加工单 ----------------------down ------------------->
            <div v-show="type    === 'machingList' || type === 'machingEdit'">
                <el-card>
                    <!-------------------------------加工单列表 ----------------------down ------------------->
                    <div v-show="type == 'machingList'">
                        <div class="handle-table1" >
                            <el-row :gutter="20" style="margin: 10px" >
                                <el-col :span = "2">
                                    <el-button type="primary" @click="addMaching">新增加工单</el-button>
                                </el-col>
                                <el-col :span="6">
                                    <el-input v-model = "lgtQuery.billno" placeholder="单号"></el-input>
                                </el-col>
                                <el-col :span="6">
                                    <el-select v-model = "lgtQuery.suppilerId" filterable  placeholder="加工单位">
                                        <el-option
                                                v-for="item in suppiler"
                                                :key="item.fitemid"
                                                :label="item.FName"
                                                :value="item.fitemid">
                                        </el-option>
                                    </el-select>
                                </el-col>
                                <el-col :span="6">
                                    <el-button type="primary" @Click="searchLgtList">查询</el-button>
                                    <el-button @Click="lgtQuery.suppilerId = '';lgtQuery.billno=''">清空</el-button>
                                </el-col>
                            </el-row>
                            <el-table
                                    ref="multipleTable"
                                    :data="lgtPage.content"
                                    tooltip-effect="dark"
                                    style="width: 100%;"
                                    @selection-change="handleSelectionChange">
                                <el-table-column type="expand">
                                    <template slot-scope="props">
                                        <el-table :data="props.row.details" border >
                                            <el-table-column type="expand">
                                                <template slot-scope="props1">
                                                    <el-table :data="props1.row.machings">
                                                        <el-table-column
                                                                prop="knife_type"
                                                                label="分刀"
                                                                width="140">
                                                        </el-table-column>
                                                        <el-table-column
                                                                prop="knife_weight"
                                                                label="本刀重"
                                                                width="140">
                                                        </el-table-column>
                                                        <el-table-column
                                                                prop="materia_width"
                                                                label="宽度"
                                                                width="140">
                                                        </el-table-column>
                                                        <el-table-column
                                                                prop="materia_lines"
                                                                label="条数"
                                                                width="140">
                                                        </el-table-column>
                                                        <el-table-column
                                                                prop="materia_section"
                                                                label="段"
                                                                width="140">
                                                        </el-table-column>
                                                        <el-table-column
                                                                prop="materia_len"
                                                                label="长度"
                                                                width="140">
                                                        </el-table-column>
                                                    </el-table>
                                                </template>
                                            </el-table-column>
                                            <el-table-column
                                                    prop="fMaterialNumber"
                                                    label="加工材料名称代码"
                                                    width="140">
                                            </el-table-column>
                                            <el-table-column
                                                    prop="fMaterialName"
                                                    label="加工材料名称"
                                                    width="140">
                                            </el-table-column>
                                            <el-table-column
                                                    prop="fMaterialModel"
                                                    label="规格"
                                                    width="140">
                                            </el-table-column>
                                            <el-table-column
                                                    prop="fBatchNo"
                                                    label="加工材料批次"
                                                    width="140">
                                            </el-table-column>
                                            <el-table-column
                                                    prop="fAuxPropID"
                                                    label="辅助属性"
                                                    width="140">
                                            </el-table-column>
<!--                                            <el-table-column-->
<!--                                                    prop="fConvRate"-->
<!--                                                    label="转换率"-->
<!--                                                    width="140">-->
<!--                                            </el-table-column>-->
<!--                                            <el-table-column-->
<!--                                                    prop="fSecUnitNumber"-->
<!--                                                    label="辅助单位id"-->
<!--                                                    width="140">-->
<!--                                            </el-table-column>-->
<!--                                            <el-table-column-->
<!--                                                    prop="fSecUnitName"-->
<!--                                                    label="辅助单位"-->
<!--                                                    width="140">-->
<!--                                            </el-table-column>-->
                                            <el-table-column
                                                    prop="fBUQty"
                                                    label="重量"
                                                    width="140">
                                            </el-table-column>
                                            <el-table-column
                                                    prop="fStockName"
                                                    label="仓库"
                                                    width="140">
                                            </el-table-column>
                                        </el-table>
                                    </template>
                                </el-table-column>
                                <el-table-column
                                        prop="billno"
                                        label="单号"
                                        width="140">
                                </el-table-column>
                                <el-table-column
                                        prop="suppilerId"
                                        label="加工单位"
                                        :formatter="f_suppiler"
                                        width="140">
                                </el-table-column>
                                <el-table-column
                                        prop="code"
                                        label="编号"
                                        width="140">
                                </el-table-column>
                                <el-table-column
                                        prop="payDate"
                                        label="汇款日期"
                                        :formatter="f_date"
                                        width="140">
                                </el-table-column>
                                <el-table-column
                                        prop="inStockId"
                                        label="入库仓库"
                                        :formatter="f_stock"
                                        width="140">
                                </el-table-column>
                                <el-table-column
                                        prop="outStockId"
                                        label="出库仓库"
                                        :formatter="f_stock"
                                        width="140">
                                </el-table-column>
                                <el-table-column
                                        prop="updateBy"
                                        label="更新人"
                                        width="140">
                                </el-table-column>
                                <el-table-column
                                        prop="updateTime"
                                        :formatter="f_date"
                                        label="更新时间"
                                        width="140">
                                </el-table-column>
                                <el-table-column
                                        prop="status"
                                        :formatter="f_status"
                                        label="单据状态"
                                        width="80">
                                </el-table-column>
                                <el-table-column label="操作" width="180" >
                                    <template slot-scope="scope">
                                        <el-button
                                                type="text"
                                                :disabled="scope.row.status != 'draft'"
                                                icon="el-icon-delete"
                                                @click="delMas(scope.row,scope.$index)"
                                        >删除</el-button>
                                        <span style="margin-right: 5px;margin-left: 5px"></span>
                                        <el-button
                                                type="text"
                                                :disabled="scope.row.status != 'draft'"
                                                icon="el-icon-edit"
                                                @click="editMas(scope.row)"
                                        >编辑</el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                            <el-pagination
                                    background
                                    layout="prev, pager, next"
                                    :page-size="lgtQuery.size"
                                    :current-page.sync = "lgtQuery.index"
                                    @current-change="searchLgtList"
                                    :total="lgtPage.totalElements">
                            </el-pagination>
                        </div>
                    </div>
                    <!-------------------------------加工单列表 ----------------------up ------------------->
                    <div v-show="type=='machingEdit'">
                        <!-------------------------------加工单 主表----------------------down ------------------->
                        <div class="handle-box">
                            <el-form ref="mas" :model="mas" label-width="80px" label-position="left">
                                <!-------------------------------按钮 ----------------------down------------------->
                                <el-row style="margin: 10px">
                                    <el-col :span="21">
                                        <el-button type="primary" @click="type = 'machingList'">返回</el-button>
                                        <el-button type="primary" @click="saveDraft">保存草稿</el-button>
                                        <el-button type="warning" @click="process">生成单据</el-button>
                                    </el-col>
                                </el-row>
                                <el-row>
                                    <el-row :gutter="24">
                                        <el-col :span="6">
                                            <el-form-item label="公司">
                                                <el-select v-model = "mas.companyId" filterable placeholder="请选择公司">
                                                    <el-option
                                                            v-for="item in company"
                                                            :key="item.FItemID"
                                                            :label="item.FName"
                                                            :value="item.FItemID">
                                                    </el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="6">
                                            <el-form-item label="付款日期">
                                                <el-date-picker
                                                        v-model="mas.payDate"
                                                        type="date"
                                                        placeholder="选择付款日期">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="6">
                                            <el-form-item label="加工单位">
                                                <el-select v-model = "mas.suppilerId" filterable  placeholder="请选择加工单位">
                                                    <el-option
                                                            v-for="item in suppiler"
                                                            :key="item.fitemid"
                                                            :label="item.FName"
                                                            :value="item.fitemid">
                                                    </el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="6">
                                            <el-form-item label="日期">
                                                <el-date-picker
                                                        v-model="mas.date"
                                                        type="date"
                                                        placeholder="选择日期">
                                                </el-date-picker>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row :gutter="24">
                                        <el-col :span="6">
                                            <el-form-item label="单号">
                                                <el-input v-model = "mas.billno" placeholder="单号"></el-input>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="6">
                                            <el-form-item label="编号">
                                                <el-input v-model = "mas.code"  placeholder="编号"></el-input>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="6">
                                            <el-form-item label="入库仓库">
                                                <el-select v-model = "mas.inStockId" filterable placeholder="请选择入库仓库">
                                                    <el-option
                                                            v-for="item in stock"
                                                            :key="item.FItemID"
                                                            :label="item.FName"
                                                            :value="item.FItemID">
                                                    </el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                        <el-col :span="6">
                                            <el-form-item label="出库仓库">
                                                <el-select v-model = "mas.outStockId" filterable  placeholder="请选择出库仓库">
                                                    <el-option
                                                            v-for="item in stock"
                                                            :key="item.FItemID"
                                                            :label="item.FName"
                                                            :value="item.FItemID">
                                                    </el-option>
                                                </el-select>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                    <el-row>
                                        <el-col :span="18">
                                            <el-form-item label="备注">
                                                <el-input
                                                        type="textarea"
                                                        :autosize="{ minRows: 2, maxRows: 4}"
                                                        placeholder="备注:"
                                                        v-model="mas.marks">
                                                </el-input>
                                            </el-form-item>
                                        </el-col>
                                    </el-row>
                                </el-row>
                            </el-form>
                        </div>
                        <!-------------------------------加工单 主表----------------------up ------------------->
                        <!-------------------------------加工单 明细表----------------------down ------------------->
                        <div class="handle-table1">

                            <el-table
                                    :data="mas.details"
                                    style="width: 100%"
                                    border
                                    highlight-current-row="true"
                                    @current-change="handleCurrentChange"
                                    class="table">
                                <el-table-column
                                        type="index"
                                        width="45">
                                </el-table-column>
                                <el-table-column
                                        prop="fMaterialNumber"
                                        label="加工材料名称代码"
                                        width="100">
                                </el-table-column>
                                <el-table-column
                                        prop="fMaterialName"
                                        label="加工材料名称"
                                        width="160">
                                </el-table-column>
                                <el-table-column
                                        prop="fMaterialModel"
                                        label="规格"
                                        width="120">
                                </el-table-column>
                                <el-table-column
                                        prop="fBatchNo"
                                        label="加工材料批次"
                                        width="100">
                                </el-table-column>
                                <el-table-column
                                        prop="fAuxPropID"
                                        label="辅助属性"
                                        width="100">
                                </el-table-column>
<!--                                <el-table-column-->
<!--                                        prop="fConvRate"-->
<!--                                        label="转换率"-->
<!--                                        width="100">-->
<!--                                </el-table-column>-->
<!--                                <el-table-column-->
<!--                                        prop="fSecUnitNumber"-->
<!--                                        label="辅助单位id"-->
<!--                                        width="100">-->
<!--                                </el-table-column>-->
<!--                                <el-table-column-->
<!--                                        prop="fSecUnitName"-->
<!--                                        label="辅助单位"-->
<!--                                        width="100">-->
<!--                                </el-table-column>-->
                                <el-table-column
                                        prop="fBUQty"
                                        label="重量"
                                        width="140">
                                </el-table-column>
                                <el-table-column
                                        prop="fStockName"
                                        label="仓库"
                                        width="140">
                                </el-table-column>
                                <el-table-column label="操作" width="180" >
                                    <template slot-scope="scope">
                                        <el-button
                                                type="text"
                                                icon="el-icon-delete"
                                                @click="handleDel(scope.row,scope.$index)"
                                        >删除</el-button>
                                        <span style="margin-right: 5px;margin-left: 5px"></span>
                                        <el-button
                                                type="text"
                                                icon="el-icon-edit"
                                                @click="handleEdit(scope.row)"
                                        >编辑</el-button>
                                    </template>
                                </el-table-column>
                            </el-table>
                            <el-button @click = "handSel">新增</el-button>
                        </div>
                        <!-------------------------------加工单 主表----------------------up ------------------->
                    </div>
                </el-card>
            </div>
            <!-------------------------------加工单 ----------------------up ------------------->

        </el-main>
        <!-------------------------------drawer 分到 ----------------------wodn ------------------->
        <el-drawer
                :visible.sync="drawerVisible"
                size = '60%'
                :wrapperClosable = "false"
                :show-close="false"
                direction="rtl">
            <slot slot="title">
                加工选项:
                <el-radio-group v-model="machingtype" @change="selectMachingtype">
                    <el-radio label="1">单独平直</el-radio>
                    <el-radio label="2">单独分条</el-radio>
                    <el-radio label="3">分条&平直</el-radio>
                </el-radio-group>
<!--                <el-button @click="saveMachingtype">切割检查</el-button>-->
                <el-button @click="saveMachingtype">关闭</el-button>
            </slot>
            <div style="height: 800px;overflow:scroll;">
                <el-card style="margin-left: 10px;margin-right: 10px;">
                    <el-form ref="" :model="machings" label-width="80px" label-position="top">
                        <div>
                            <el-row gutter="24" v-if="machingtype == 1">
                                <el-col :span = 2>
                                    <el-form-item label="序号" >
                                    </el-form-item>
                                </el-col>
                                <el-col :span = 3>
                                    <el-form-item label="长度" >
                                    </el-form-item>
                                </el-col>
                                <el-col :span = 3>
                                    <el-form-item label="件数">
                                    </el-form-item>
                                </el-col>
                                <el-col :span = 3>
                                    <el-form-item label="包数" >
                                    </el-form-item>
                                </el-col>
                                <el-col :span = 2>
                                    <el-form-item label="重量" >
                                    </el-form-item>
                                </el-col>
                                <el-col :span = 3 >
                                    <el-form-item label="单价" >
                                    </el-form-item>
                                </el-col>
                                <el-col :span = 3 >
                                    <el-form-item label="零件号" >
                                    </el-form-item>
                                </el-col>
                                <el-col :span = 3>
                                    <el-form-item label="备注" >
                                    </el-form-item>
                                </el-col>
                                <el-col :span = 2>
                                    <el-form-item label="操作">
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <div v-if="machingtype == 1">
                                <el-row gutter="24" type="flex" align="middle"  v-for="(item,index) in machings">
                                    <el-col :span = 2>
                                        <el-form-item >
                                            <div>{{index}}</div>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span = 3>
                                        <el-form-item>
                                            <el-input v-model="item.materia_len"  @change="lenChange(item)"  @keyup.enter.native="addStraight(index)"></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span = 3>
                                        <el-form-item>
                                            <el-input v-model="item.materia_number"  @keyup.enter.native="addStraight(index)"></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span = 3>
                                        <el-form-item>
                                            <el-input v-model="item.package_number"  @keyup.enter.native = "addStraight(index)"></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span = 2>
                                        <el-form-item>
                                           {{item.materia_weight}}
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span = 3>
                                        <el-form-item>
                                            <el-input v-model="item.materia_price"  @keyup.enter.native = "addStraight(index)"></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span = 3>
                                        <el-form-item>
                                            <el-input v-model="item.part_number"  @keyup.enter.native = "addStraight(index)"></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span = 3>
                                        <el-form-item>
                                            <el-input v-model="item.remarks"  @keyup.enter.native = "addStraight(index)"></el-input>
                                        </el-form-item>
                                    </el-col>
                                    <el-col :span = 2>
                                        <el-form-item>
                                            <el-button @click="machings.splice(index,1)">删除</el-button>
                                        </el-form-item>
                                    </el-col>
                                </el-row>
                            </div>
                            <el-row gutter="24" v-if="machingtype == 2">
                                <el-col :span = 2>
                                    <el-form-item label="序号" >
                                    </el-form-item>
                                </el-col>
                                <el-col :span = 2>
                                    <el-form-item label="分刀" >
                                    </el-form-item>
                                </el-col>
                                <el-col :span = 3>
                                    <el-form-item label="本刀重">
                                    </el-form-item>
                                </el-col>
                                <el-col :span = 3>
                                    <el-form-item label="段" >
                                    </el-form-item>
                                </el-col>
                                <el-col :span = 2>
                                    <el-form-item label="长度" >
                                    </el-form-item>
                                </el-col>
                                <el-col :span = 3 v-show="machingtype != 1">
                                    <el-form-item label="宽度" >
                                    </el-form-item>
                                </el-col>
                                <el-col :span = 3 v-show="machingtype != 1">
                                    <el-form-item label="条数" >
                                    </el-form-item>
                                </el-col>
                                <el-col :span = 3>
                                    <el-form-item label="产品类型" >
                                    </el-form-item>
                                </el-col>
                                <el-col :span = 2>
                                    <el-form-item label="操作">
                                    </el-form-item>
                                </el-col>
                            </el-row>
                            <div v-if="machingtype == 2">
                                <el-row type="flex" align="middle"  v-for="(item,index) in machings">
                                    <el-col :span=12 >
                                        <el-row gutter="24" type="flex" align="middle">
                                            <el-col :span = 2>
                                                <el-form-item >
                                                    <div>{{index}}</div>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span = 4>
                                                <el-form-item>
                                                    <el-input v-model="item.knife_type"   @keyup.enter.native="addMachingLine(index)"></el-input>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span = 6>
                                                <el-form-item>
                                                    <el-input v-model="item.knife_weight"  @change="weightChange(item)"  @keyup.enter.native="addMachingLine(index)"></el-input>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span = 6>
                                                <el-form-item>
                                                    <el-input v-model="item.materia_section"  @keyup.enter.native = "addMachingLine(index)"></el-input>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span = 6>
                                                <el-form-item>
                                                    {{item.materia_len}}
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                    </el-col>
                                    <el-col :span=12>
                                        <el-row gutter="24" v-for="(it,ind) in item.list">
                                            <el-col :span =6>
                                                <el-form-item>
                                                    <el-input v-model="it.materia_width" :disabled="machingtype == '1'"  @keyup.enter.native="addMachingLineList(index)"></el-input>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span = 6>
                                                <el-form-item>
                                                    <el-input v-model="it.materia_lines" :disabled="machingtype == '1'"   @keyup.enter.native="addMachingLineList(index)"></el-input>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span = 6>
                                                <el-form-item>
                                                    <el-select v-model="it.materia_type" placeholder="请选择">
                                                        <el-option
                                                                v-for="ent in materia_types"
                                                                :key="ent.value"
                                                                :label="ent.label"
                                                                :value="ent.value">
                                                        </el-option>
                                                    </el-select>
                                                </el-form-item>
                                            </el-col>
                                            <el-col :span = 4>
                                                <el-form-item>
                                                    <el-button @click="machings.splice(ind,1)">删除</el-button>
                                                </el-form-item>
                                            </el-col>
                                        </el-row>
                                    </el-col>
                                </el-row>
                            </div>

                            <el-row>
                                <el-button @click="machings.push({materia_type:'produce'})">增加</el-button>
                                <el-button @click="generate">生成切割数据</el-button>
                            </el-row>
                        </div>
                    </el-form>
                </el-card>
                <el-card style="margin-left: 10px;margin-right: 10px;margin-bottom: 200px">
                    <el-table
                            ref="multipleTable"
                            :data="outcome"
                            border
                            empty-text = "分割结果，待完善"
                            tooltip-effect="dark"
                            style="width: 100%;">
                        <el-table-column
                                prop="fMaterialNumber"
                                label="编码"
                                width="140">
                        </el-table-column>
                        <el-table-column
                                prop="fMaterialModel"
                                label="规格"
                                width="140">
                        </el-table-column>
                        <el-table-column
                                prop="fMaterialName"
                                label="名称"
                                width="140">
                        </el-table-column>
                        <el-table-column
                                prop="count"
                                label="数量"
                                width="140">
                        </el-table-column>
                        <el-table-column
                                prop="weight"
                                label="重量"
                                width="140">
                        </el-table-column>
                        <el-table-column
                                prop="msg"
                                label="信息"
                                width="140">
                        </el-table-column>
                    </el-table>
                </el-card>
            </div>
        </el-drawer>
        <!-------------------------------drawer 分到 ----------------------up ------------------->
        <!-------------------------------dialog 存储过程获取产品列表 ----------------------wodn ------------------->
        <el-dialog :visible.sync="dialogVisible" width="80%" v-loading="loading">
            <div class="handle-table1" >
                <el-row :gutter="20" style="margin-bottom: 10px" >
                    <el-col :span="2.5">
                        <el-button type="success" @click="selStockQuality">选择&返回</el-button>
                    </el-col>
                    <el-col :span="6">
                        <el-input v-model = "SQ.materialname" placeholder="物料"></el-input>
                    </el-col>
                    <el-col :span="6">
                        <el-input v-model = "SQ.materialmodel" placeholder="产品类型"></el-input>
                    </el-col>
                    <el-col :span="6">
                        <el-button type="primary" @Click="getStockQuality">查询</el-button>
                    </el-col>
                </el-row>
                <el-table
                        ref="multipleTable"
                        :data="stockQuality.slice(SQ.currentPage*5-5,SQ.currentPage*5)"
                        tooltip-effect="dark"
                        style="width: 100%;"
                        @selection-change="handleSelectionChange">
                    <el-table-column
                            type="selection"
                            width="45">
                    </el-table-column>
                    <el-table-column
                            prop="fMaterialNumber"
                            label="加工材料名称代码"
                            width="120">
                    </el-table-column>
                    <el-table-column
                            prop="fMaterialName"
                            label="加工材料名称"
                            width="140">
                    </el-table-column>
                    <el-table-column
                            prop="fMaterialModel"
                            label="规格"
                            width="120">
                    </el-table-column>
                    <el-table-column
                            prop="fBatchNo"
                            label="加工材料批次"
                            width="120">
                    </el-table-column>
                    <el-table-column
                            prop="fAuxPropID"
                            label="辅助属性"
                            width="100">
                    </el-table-column>
<!--                    <el-table-column-->
<!--                            prop="fConvRate"-->
<!--                            label="转换率"-->
<!--                            width="100">-->
<!--                    </el-table-column>-->
<!--                    <el-table-column-->
<!--                            prop="fSecUnitNumber"-->
<!--                            label="辅助单位id"-->
<!--                            width="100">-->
<!--                    </el-table-column>-->
<!--                    <el-table-column-->
<!--                            prop="fSecUnitName"-->
<!--                            label="辅助单位"-->
<!--                            width="140">-->
<!--                    </el-table-column>-->
                    <el-table-column
                            prop="fBUQty"
                            label="重量"
                            width="140">
                    </el-table-column>
                    <el-table-column
                            prop="fStockName"
                            label="仓库"
                            width="140">
                    </el-table-column>
                </el-table>
                <el-pagination
                        background
                        layout="prev, pager, next"
                        page-size="5"
                        @current-change="SQcurrentChange"
                        :total="stockQuality.length">
                </el-pagination>
            </div>
        </el-dialog>
        <!-------------------------------drawer 存储过程获取产品列表 ----------------------up ------------------->
    </el-container>
</div>

</body>

<script>
    new Vue({
        el: '#app',
        created(){
            //设置全局的
            var instance = axios.create({
                timeout: 20000,
                //headers: { 'Content-Type': 'application/x-www-form-urlencoded'}
                headers: {'Content-Type': 'application/json;charset=utf-8'}
            });
            this.$axios = instance;

            this.getAllBase();
        },
        mounted(){
            //this.timer = setInterval(this.fleshList, 1000);
        },
        beforeDestroy() {

        },
        data() {
            const validatePassword = (rule, value, callback) => {
                if (value.length < 6) {
                    callback(new Error('密码长度至少6位'))
                } else {
                    callback()
                }
            }
            return {
                lgtQuery:{
                    index: 1,
                    size: 5,
                    billno:'',
                    suppilerId:'',
                },
                lgtPage:[],
                company:[],
                emp:[],
                suppiler:[],
                stock:[],
                icitem:[],
                $axios:{},
                muser:{},
                machingtype:0,
                multipleSelection:[],
                editVisible:false,
                dialogVisible:false,
                drawerVisible:false,
                stockQuality:[],
                type:'machingList',
                form:{},
                mas:{details:[]},
                currentRow:{},
                outcome:[],
                query: {
                    pageIndex: 1,
                    pageSize: 10,
                    entity: {
                        name: ''
                    }
                },
                SQ:{
                    materialname:'',
                    materialmodel:'',
                    currentPage:1,
                },
                page: [],
                loading: false,
                passwordType: 'password',
                redirect: undefined,
                test:'',
                straights:{},
                slitting:{},
                machings:[],
                materia_types:[{
                    value: 'produce',
                    label: '成品'
                }, {
                    value: 'surplus',
                    label: '余卷'
                }, {
                    value: '选项3',
                    label: '余边（齐边）'
                }, {
                    value: '选项4',
                    label: '余边（自由边）'
                }, {
                    value: '选项5',
                    label: '边料'
                }, {
                    value: '选项5',
                    label: '边丝'
                }],
                knifeTypes:['A','B','C'],
                len6:{
                    password:[{ required: true, trigger: 'blur', validator: validatePassword }],
                    n_password1:[{ required: true, trigger: 'blur', validator: validatePassword }],
                    n_password2:[{ required: true, trigger: 'blur', validator: validatePassword }]
                }
            }
        },
        methods:{
            handleSelectionChange(val) {
                this.multipleSelection = val
            },
            saveEdit(){

            },
            generate(){
                console.log('generate')
                let outcomes = [];
                let chang = 0;
                let kuang = 0;
                let arr = this.currentRow.fMaterialModel.split('*')
                let fbuqty = this.currentRow.fBUQty;
                for(let it of this.machings){
                    if(this.machingtype == '1'){
                        let produce = {fMaterialName:this.currentRow.fMaterialName,fMaterialModel:this.currentRow.fMaterialModel};
                        produce.fMaterialModel = arr[0] + '*' +   arr[1] + '*' + it.materia_len
                        produce.count = it.materia_number;
                        produce.weight =it.materia_weight;
                        outcomes.push(produce);
                       // chang += it.materia_section * it.materia_len
                    }else if(this.machingtype == '2'){
                        for(let ent of it.list){
                            let produce = {fMaterialName:this.currentRow.fMaterialName,fMaterialModel:this.currentRow.fMaterialModel};
                            produce.fMaterialModel = arr[0] + '*' +  ent.materia_width + '*' +  arr[2]
                            produce.count = ent.materia_lines;
                            produce.weight = Math.round(fbuqty/arr[1]* ent.materia_width)
                            outcomes.push(produce);
                        }
                    }else{
                        let produce = {fMaterialName:this.currentRow.fMaterialName,fMaterialModel:this.currentRow.fMaterialModel};
                        let materia_width = it.materia_width;
                        let materia_lines = it.materia_lines;
                        let materia_section = it.materia_section;
                        let materia_len = it.materia_len;
                        produce.fMaterialModel = arr[0] + '*' + materia_width + '*' + materia_len
                        produce.count = materia_lines * materia_section;
                        let totalWeight = Math.round(fbuqty/arr[1]*materia_width)
                        produce.weight = Math.round(it.knife_weight)
                        let dueWeight = totalWeight - produce.weight * materia_section
                        if(dueWeight<0){
                            this.error('错误重量!');
                            return;
                        }
                        outcomes.push(produce);
                        let dueprod = {fMaterialName:this.currentRow.fMaterialName};
                        materia_width = Math.round(dueWeight * arr[2]/totalWeight);
                        dueprod.fMaterialModel = arr[0] + '*' + materia_width + '*' + materia_len
                        dueprod.count = materia_section;
                        dueprod.weight = dueWeight;
                        if(dueprod.weight > 0){
                            outcomes.push(dueprod);
                        }
                    }
                }
                this.checkIcItem(outcomes);
            },
            addMaching(){
                this.type = 'machingEdit';
                this.mas = {details:[]}
            },
            SQcurrentChange(val){
                this.SQ.currentPage = val;
            },
            selStockQuality(){
                this.dialogVisible = false;
                for(let it of this.multipleSelection){
                    this.mas.details.push(it);
                }
            },
            handleSearch() {
                this.$set(this.query, 'pageIndex', 1)
                this.getData()
            },
            // 分页导航
            handlePageChange(val) {
                this.$set(this.query, 'pageIndex', val)
                this.getData()
            },
            handleCurrentChange(val){
                //this.currentRow = val;
                //this.drawerVisible = true;
            },
            weightChange(item){
                let fbuqty = this.currentRow.fBUQty;
                let arr = this.currentRow.fMaterialModel.split('*')
                if(arr[1] == 'C'){
                    arr[1] = fbuqty*1000/7.9/arr[0]/arr[2];
                    item.materia_len = Math.round(item.knife_weight * arr[1]/fbuqty);
                }
                if(arr[2] == 'C'){
                    arr[2] = fbuqty*1000/7.9/arr[0]/arr[1];
                    item.materia_len = Math.round(item.knife_weight * arr[2]/fbuqty);
                }
                this.machings = JSON.parse(JSON.stringify(this.machings));
            },
            lenChange(item){
                let fbuqty = this.currentRow.fBUQty;
                let arr = this.currentRow.fMaterialModel.split('*')
                if(arr[1] == 'C'){
                    arr[1] = fbuqty*1000/7.9/arr[0]/arr[2];
                    item.materia_weight = Math.round(item.materia_len * fbuqty/arr[2]);
                }
                if(arr[2] == 'C'){
                    arr[2] = fbuqty*1000/7.9/arr[0]/arr[1];
                    item.materia_weight = Math.round(item.materia_len * fbuqty/arr[2]);
                }
                this.machings = JSON.parse(JSON.stringify(this.machings));
            },
            addStraight(index){
                let fbuqty = this.currentRow.fBUQty;
                this.machings.splice(index+1);
                let arr = this.currentRow.fMaterialModel.split('*')
                if(arr[1] == 'C'){
                    arr[1] = fbuqty*1000/7.9/arr[0]/arr[2];
                }
                if(arr[2] == 'C'){
                    arr[2] = Math.round(fbuqty*1000/7.9/arr[0]/arr[1]);
                }
                let sup = {};
                let len = arr[2];
                for(let it of this.machings){
                    len -= it.materia_len * it.materia_number;
                }
                if(len>0){
                    sup.materia_len = len
                    sup.materia_weight = Math.round(len * fbuqty/arr[2]);
                    sup.materia_number = 1;
                    sup.package_number = 1;
                    this.machings.push(sup);
                }else if(len == 0){
                    this.error('已经切割完成，不能再切割!')
                }else{
                    this.error('切割数据填写错误!')
                }
                this.generate();
            },
            addMachingLine(index){
                console.log(1)
                this.machings.splice(index+1);
                let fbuqty = this.currentRow.fBUQty;
                let arr = this.currentRow.fMaterialModel.split('*')
                if(arr[1] == 'C'){
                    arr[1] = fbuqty*1000/7.9/arr[0]/arr[2];
                }
                if(arr[2] == 'C'){
                    arr[2] = fbuqty*1000/7.9/arr[0]/arr[1];
                }
                let sup = {};
                let weight = fbuqty;
                if(this.machingtype == '1'){
                    let len = arr[2] ;
                    for(let ma of this.machings){
                        if(ma.knife_weight && ma.materia_section && ma.knife_type ){
                            weight -= ma.knife_weight * ma.materia_section;
                        }else{
                            this.error('请把数据填写完整!')
                            this.generate();
                            return;
                        }
                    }
                    if(weight>0){
                        sup.materia_len = Math.round(weight * arr[2]/fbuqty);
                        sup.knife_weight = weight;
                        sup.materia_type = 'produce';
                        sup.knife_type='A'
                        sup.materia_section = 1;
                        this.machings.push(sup);
                    }else if(weight == 0){
                        this.error('已经切割完成，不能再切割!')
                    }else{
                        this.error('切割数据填写错误!')
                    }
                    this.generate();
                }else if(this.machingtype == '2'){
                    for(let ma of this.machings){
                        if(ma.knife_weight && ma.materia_section && ma.knife_type ){
                            weight -= ma.knife_weight * ma.materia_section;
                        }else{
                            this.error('请把数据填写完整!')
                            this.generate();
                            return;
                        }
                    }
                    if(weight>0){
                        sup.materia_len = Math.round(weight * arr[2]/fbuqty);
                        sup.knife_weight = weight;
                        sup.list = [{materia_type:'produce'}]
                        sup.knife_type='A'
                        sup.materia_section = 1;
                        this.machings.push(sup);
                    }else if(weight == 0){
                        this.error('已经切割完成，不能再切割!')
                    }else{
                        this.error('切割数据填写错误!')
                    }
                    let width = arr[1] ;
                }else if(this.machingtype == '3'){
                    let width = arr[1] ;
                    for(let ma of this.machings){
                        if(ma.materia_width && ma.materia_lines){
                            width -= ma.materia_width * ma.materia_lines;
                            weight -=  Math.round(fbuqty/arr[1]*ma.materia_width * ma.materia_lines);
                        }else{
                            this.error('请把数据填写完整!')
                            this.generate();
                            return;
                        }
                    }
                    if(weight > 0 && width > 0){
                        sup.materia_len = Math.round(weight * arr[2]/fbuqty);
                        sup.knife_weight = weight;
                        sup.knife_type='A'
                        sup.materia_section = 1;
                        sup.materia_width = width;
                        sup.materia_type = 'produce';
                        sup.materia_lines = 1;
                        this.machings.push(sup);
                    }else if(weight == 0 && width == 0){
                        this.error('已经切割完成，不能再切割!')
                    }else{
                        this.error('切割数据填写错误!')
                    }
                    this.generate();
                }else{
                    this.error('请选择切割类型!');
                }
            },
            addMachingLineList(index){
                let arr = this.currentRow.fMaterialModel.split('*')
                let sup = {};
                let width = arr[1] ;
                if(this.machingtype == '2'){
                    for(let ma of this.machings[index].list){
                        if(ma.materia_width && ma.materia_lines){
                            width -= ma.materia_width * ma.materia_lines;
                        }else{
                            this.error('请把数据填写完整!')
                            this.generate();
                            return;
                        }
                    }
                    if(width>0){
                        sup.materia_width = width;
                        sup.materia_lines = 1;
                        sup.materia_type = 'produce';
                        this.machings[index].list.push(sup);
                    }else if(width == 0){
                        this.error('已经切割完成，不能再切割!')
                    }else{
                        this.error('切割数据填写错误!')
                    }
                }
                this.generate();
            },
            changeMateriaType(type,index){
                if(type == 'surplus'){
                    let fbuqty = this.currentRow.fBUQty;
                    let arr = this.currentRow.fMaterialModel.split('*')
                    if(arr[1] == 'C'){
                        arr[1] = fbuqty*1000/7.9/arr[0]/arr[2];
                    }
                    if(arr[2] == 'C'){
                        arr[2] = fbuqty*1000/7.9/arr[0]/arr[1];
                    }
                    let sup = this.machings.splice(index,1);
                    if(this.machingtype == '1'){
                        let len = arr[2] ;
                        let weight = fbuqty;
                        for(let ma of this.machings){
                            ma.materia_len = arr[1]*ma.knife_weight/fbuqty;
                            len -= ma.materia_len * ma.materia_section;
                            weight -= ma.knife_weight * ma.materia_section;
                        }
                        sup.materia_len = len;
                        sup.knife_weight = weight;
                        sup.materia_type = 'surplus';
                        sup.knife_type='FD'
                        sup.materia_section = 1;
                        this.machings.push(sup);
                    }
                }
            },
            handleEdit(row){
                this.currentRow = row;
                if(this.currentRow.machingtype != undefined){
                    this.machingtype = this.currentRow.machingtype;
                }
                if(this.currentRow.machings){
                    this.machings = this.currentRow.machings;
                }else{
                    this.machings = [];
                }
                if(this.currentRow.outcome){
                    this.outcome = this.currentRow.outcome;
                }else{
                    this.outcome = [];
                }
                this.drawerVisible = true;
            },
            handleDel(row, index){
                this.mas.details.splice(index,1);
            },
            handSel(){
                if(this.mas.outStockId == undefined){
                    this.error("请先选择出库仓库");
                    return;
                }
                this.dialogVisible = true;
            },
            editMas(row){
                this.mas = row;
                if(this.mas.details == undefined){
                    this.mas.details = []
                }
                this.type = 'machingEdit';
            },
            selectMachingtype(val){
                this.currentRow.machings = [];
                if(this.machingtype == '1'){
                    this.machings = [{materia_type:'produce'}];
                }else if(this.machingtype == '2'){
                    this.machings = [{'list':[{materia_type:'produce'}]}];
                }
                this.currentRow.straights = {materia_price:''};
                //this.generate();
            },
            saveMachingtype(){
                console.log('saveMachingtype')
                this.currentRow.machingtype = this.machingtype;
                this.currentRow.machings = this.machings;
                this.currentRow.outcome = this.outcome;
                this.drawerVisible = false;
            },
            closeDrawer(){
                this.drawerVisible = false;
            },
/******************************************数据格式化formater down*******************************************/
            f_suppiler(row, column, cellValue, index){
                for(let it of this.suppiler){
                    if(it.fitemid == cellValue){
                        return it.FName;
                    }
                }
                return "";
            },
            f_stock(row, column, cellValue, index){
                for(let it of this.stock){
                    if(it.FItemID == cellValue){
                        return it.FName;
                    }
                }
                return "";
            },
            f_status(row, column, cellValue, index){
                if(cellValue == 'draft'){
                    return '草稿';
                }
                return "完成加工";
            },
            //时间格式化
            f_date(row, column, cellValue, index){
                if(cellValue){
                    var date = new Date(cellValue) //时间戳为10位需*1000，时间戳为13位的话不需乘1000
                    var Y = date.getFullYear() + '-'
                    var M = (date.getMonth()+1 < 10 ? '0'+(date.getMonth()+1) : date.getMonth()+1) + '-'
                    var D = date.getDate() + ' '
                    var h = date.getHours() + ':'
                    var m = date.getMinutes() + ':'
                    var s = date.getSeconds()
                    return Y+M+D+h+m+s
                }
                return '';
            },

            /******************************************数据格式化formater up*******************************************/


/******************************************请求 down*******************************************/
            saveDraft(){
                let there = this;
                this.mas.status = 'draft';
                this.post('/lgtMas/save',this.mas,function (res) {
                    if(200 === res.code){
                        there.loading = false;
                        there.type = 'machingList';
                        there.success(res.message);
                        there.searchLgtList();
                    }else {
                        there.loading = false;
                        there.error(res.message);
                        setTimeout(window.location.href='/main',3);
                    }
                })
            },
            delMas(row, index){
                let there = this;
                this.get('/lgtMas/del?id='+row.id,function (res) {
                    if(200 === res.code){
                        there.loading = false;
                        there.success(res.message);
                        there.searchLgtList()
                    }else {
                        there.loading = false;
                        there.error(res.message);
                    }
                })
            },
            searchLgtList(){
                let there = this;
                this.post('/lgtMas/query',this.lgtQuery,function (res) {
                    if(200 === res.code){
                        there.lgtPage= res.data.page;
                    }else {
                        there.error(res.message);
                        setTimeout(window.location.href='/main',3);
                    }
                })
            },
            getMuser(){
                let there = this;
                this.get('/user/getMuser',function (res) {
                    if(200 === res.code){
                        there.muser = res.data.muser;
                    }else {
                        there.error(res.message);
                        setTimeout(window.location.href='/main',3);
                    }
                })
            },
            getStockQuality(){
                let there = this;
                let param = 'materialname='+this.SQ.materialname+'&materialmodel='+this.SQ.materialmodel+'&fStockId='+this.mas.outStockId
                this.get('/stockQuality/getStockQuality?'+param,function (res) {
                    console.log(res)
                    if(200 === res.code){
                        there.stockQuality = res.data.stockQuality;
                    }else {
                        there.error(res.message)
                    }
                })
            },

            checkIcItem(outcomes){
                let there = this;
                this.post('/basedata/checkIcItem',outcomes,function (res) {
                    if(200 === res.code){
                        there.outcome = res.data.outcome;
                    }else {
                        there.error(res.message)
                    }
                })
            },

            saveMuser(){
                let there = this;
                let user = this.muser;
                if(this.muser.n_password1 == this.muser.n_password2){
                    this.post('/user/saveMuser',this.muser, function (res) {
                        if(200 === res.code){
                            there.success(res.message);
                            there.type='';
                            there.editVisible=false;
                        }else {
                            there.error(res.message)
                        }
                    })
                }else{
                    there.success('新密码不一致');
                }
            },
            getAllBase(){
                let there = this;
                this.get('/basedata/getAllBase',function (res) {
                    if(200 === res.code){
                        there.getMuser();
                        there.company = res.data.company;
                        there.emp = res.data.emp;
                        there.suppiler = res.data.suppiler;
                        there.stock = res.data.stock;
                        there.icitem = res.data.icitem;
                    }else {
                        there.error(res.message)
                    }
                })
            },
            process(){
                let there = this;
                this.get('/lgtMas/finish?id='+this.mas.id,function (res) {
                    if(200 === res.code){
                        there.success('保存成功')
                        there.type = 'machingList';
                        there.searchLgtList();
                    }else {
                        there.error(res.message)
                    }
                })
            },
            post(url,data,callback){
                this.loading = true;
                let there = this;
                this.$axios.post(url,JSON.stringify(data)).then(function (res) {
                    callback(res.data)
                    there.loading = false;
                }).catch(function (err) {
                    there.loading = false;
                    there.error(err)
                });
            },
            get(url,callback) {
                this.loading = true;
                let there = this;
                this.$axios.get(url).then(function (res) {
                    callback(res.data)
                    there.loading = false;
                }).catch(function (err) {
                    console.log(err);
                    there.loading = false;
                    there.error(err)
                });

            },
            error(mes){
                this.$message({
                    message: mes,
                    type: 'error'
                });
            },
            success(mes){
                this.$message({
                    message: mes,
                    type: 'success'
                });
            }
        },
        computed(){
        }
    })
</script>
<style>
    #body {
        margin: 0;
        padding: 0;
        background-color: #f2f2f2;
    }
    .c_head{
        background-color: #ffffff;
    }
    .c_header_left{
        float: left;
    }
    .c_header_right{
        float: right;
        margin: 10px;
    }
    .el-menu-item{
        font-weight: bold;
    }
    .c_menu_item{
        font-size: 35px;
        margin-left: 50px;
        margin-right: 50px;
    }
    .c_form_btn{
        float: right;
        margin-right: 50px;
    }
    .c_form{
        margin-bottom: 50px;
    }
    .handle-box {
        margin: 20px;
    }
    .handle-input {
        margin: 10px;
        width: 300px;
        display: inline-block;
    }
    .table {
        width: 100%;
        font-size: 14px;
    }
</style>
</html>